<template>
  <el-dialog :title="form.id ? '编辑权限' : '新增权限点'"  :visible.sync="showPer" class="mydiolog">
    <el-form :model="form">
      <el-form-item label="权限名称" label-width="120px">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="权限标识" label-width="120px">
        <el-input v-model="form.code"></el-input>
      </el-form-item>
      <el-form-item label="权限描述" label-width="120px">
        <el-input v-model="form.description"></el-input>
      </el-form-item>
      <el-form-item label="企业可见" label-width="120px">
        <el-switch v-model="form.delivery"></el-switch>
      </el-form-item>
      <el-form-item class="footer">
        <el-button type="primary" @click="submit">确认</el-button>
        <el-button @click="cancle">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { getPerDetailApi, updatePerApi ,addPerApi} from '@/api/permission'
export default {
  props: ['showPer'],
  data () {
    return {
      form: {
          
      }
    }
  },
  methods: {
    //根据id获得数据
     async getPerDetail(id){
        const res =  await getPerDetailApi(id)
        console.log(res);
        this.form = res.data
    },
    async submit () {
        if(this.form.id){
            //编辑信息
            //提交数据
        await updatePerApi(this.form)
        }else{
            //新增权限点
            await addPerApi(this.form)
        }
        this.$message.success('修改成功')
        this.cancle()
        //更新数据
        this.$emit('updata')
    },
    cancle () {
        this.$emit('update:showPer', false);
        this.form = {}
    },
    getData(type,pid){
        this.form.type = type
        this.form.pid = pid
    }
  }
}
</script>

<style lang='scss'>
.mydiolog{
    .footer{
        text-align: center;
    }
}
</style>
